#include <iostream>
#include <map>
#include <fstream>
#include <ostream>
#include <sstream>
using namespace std;
static map<string, string> rule;
void read(const string &filename)
{
    ifstream ifs(filename);
    string line;
    while (getline(ifs, line))
    {
        string key;
        string value;
        istringstream iss(line);
        if (iss >> key)
        {
            getline(iss>>std::ws, value);
            rule[key] = value;
        }
    }
}
string transform(const string & s){
    auto it = rule.find(s);
    if(it != rule.end()){
        return it->second;
    }
    return s;

}
void ProcessFile(const string & inputFilename,const string & outputFilename){
    ifstream ifs(inputFilename);
    ofstream ofs(outputFilename);
    string line;
    while(getline(ifs,line)){
        istringstream iss(line);
        string word;
        bool firstword = true;
        while(iss >> word){
           if(!firstword){
            ofs<<" ";
           }
           ofs << transform(word);
           firstword =false;
        }
        ofs<<endl;
    }
}
void test()
{
    read("map.txt");
    ProcessFile("file.txt","output.txt");
}
int main()
{
    test();
    return 0;
}
